// Process URL
def controller = getController(params)
def action = getAction(params)
def id = getId(params)

// add necessary attributes in the request
request.controller = controller 
request.action = action
request.id = id

if (new File("WEB-INF/groovy/${controller}/${action}.groovy").exists()) {
	// follows front/controller file structure 
	include "/WEB-INF/groovy/${controller}/${action}.groovy" 
	include '/WEB-INF/includes/template.gtpl'
} 
else if (new File("WEB-INF/groovy/${params.fcpUrl}").exists() || new File("${params.fcpUrl}").exists()) {
	// default gaelyk route for .groovy and .gtpl files
	forward "/${params.fcpUrl}"
}
else {
	// Page Not Found
	request.invalidUrl = params.fcpUrl
	//forward "/index/notFound"
	forward "/failure.gtpl"
}

//Debug
if (getAllParams(params).debug) {
	html.div {
		p("Controller: ${controller}")
		p("Action: ${action}")
		p("Id: ${id}")
		p("Params: ${getAllParams(params)}")
	}
}